/**
 * Highlights the lastfm-box
 * bool = 1 highlight
 * bool = 0 unlight
 * @param boolean bool
 */
function flip_tag(bool) {
    if (bool == '1') {
        //document.form.tagTextField.style.backgroundColor="#FFFFEE";
    } else {
        if (document.form.tag.value == '' & document.form.tagTextField.value == '') {
            document.form.tagTextField.style.backgroundColor="#FFFFFF";
        }
    }
    return;
}

function unset_tag(ref) {
	if(ref.value == '') { 
		return;
	}
	unset_tag_1();
	unset_tag_2();
	setTagsColor('#000000');
	flip_tag('0');
	return;
}
function unset_tag_1(ref) {
	document.form.tag.value='';
	setTagsColor('#000000');
	return;
}

function unset_tag_2(ref) {
	document.form.tagTextField.value='';
	flip_tag('0');
	return;
}

/**
 * Highlights the favourite-artist-box
 * bool = 1 highlight
 * bool = 0 unlight
 * @param boolean bool
 */
function flip_artists(bool) {
    if (bool == '1') {
		//document.form.inputbox_artists.style.backgroundColor="#FFFFEE";
        
    } else {
        if (document.form.inputbox_artists.value == '') {
           document.form.inputbox_artists.style.backgroundColor="#FFFFFF";
        }
    }
    return;
}

function unset_artists(ref) {
	if(ref.value == '') { 
		return;
	}
	document.form.inputbox_artists.value = '';
	flip_artists('0');
	return;
}

/**
 * Highlights the favourite-artist-box
 * bool = 1 highlight
 * bool = 0 unlight
 * @param boolean bool
 */
function flip_username(bool) {
    if (bool == '1') {
        //document.form.username.style.backgroundColor="#FFFFEE";
        
    } else {
        if (document.form.username.value == '') {
            document.form.username.style.backgroundColor="#FFFFFF";
        }
    }
    return;
}

function unset_username(ref) {
	if(ref.value == '') { 
		return;
	}
	document.form.username.value = '';
	flip_username('0');
	return;
}

function flip_venue(bool) {
    if (bool == '1') {
		/*
        document.form.venue_id.style.backgroundColor="#FFFFEE";
		document.getElementById("gigsGroup").style.backgroundColor="#FFFFEE";
        document.getElementById("festivalsGroup").style.backgroundColor="#FFFFEE";
        */
    } else {
        if (document.form.venue_id.value == '') {
            document.form.venue_id.style.backgroundColor="#FFFFFF";
        }
    }
    return;
}

function setTagsColor(color) {
	// Too load-intensive?
	var allPageTags=document.getElementsByTagName("a");
	for (i = 0; i < allPageTags.length; i++) {
		if (allPageTags[i].className == "tag") {
		allPageTags[i].style.color=color;
		}
	} 
}

/**
 * Checks for entered data when refreshing the page
 * 
 
function flip_loadCheck() {
    if(document.form.username.value != '') {    
    	flip_username('1');
    } else if(document.form.inputbox_artists.value != '') {
    	flip_artists('1');
    } else if(document.form.tag.value != '') {
		flip_tag('1');
		document.getElementById('tag_' + document.form.tag.value).style.color = 'red';
	} else if(document.form.venue_id.value != '') {
		flip_venue('1');
	}
}
*/

/**
 * Toogles the visibilty of each row in the hit list
 * 
 * @param string resultatId
 * @param string resultatImg
 */
function toggleVisibility(resultatId, resultatImg, toggle){
    var obj = document.getElementById(resultatId);
	if(toggle == 'auto') {
	    if(obj.style.display == 'none')  {
	        obj.style.display = '';
	        document.images[resultatImg].src = "templates/gfx/less.gif";
	    } else {
	        obj.style.display = 'none';
	        document.images[resultatImg].src = "templates/gfx/more.gif";
	    }
	} else if(toggle == '') {
		obj.style.display = '';
	    document.images[resultatImg].src = "templates/gfx/less.gif";
		
	} else if(toggle == 'none') {
		obj.style.display = 'none';
	    document.images[resultatImg].src = "templates/gfx/more.gif";
	}
	
    return;
}

function xmlHttpInit() {
	var xmlHttp;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp = new XMLHttpRequest();
	  } catch (e) {
	  // Internet Explorer
	  try {
	    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	    	try {
	    	  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    	} catch (e) {
	      		alert("Your browser does not support AJAX!");
	      		return false;
	        }
	    }
	 }
	 return xmlHttp;
}

function ajaxShowArtistBio(artist, id) {
	var xmlHttp = xmlHttpInit();
	xmlHttp.onreadystatechange = function() {
    	if(xmlHttp.readyState == 4) {
      		document.getElementById("artistBio_" + id).innerHTML=xmlHttp.responseText;
      	}
    }
  	xmlHttp.open("GET", "ajax.php?artist=" + artist, true);
  	xmlHttp.send(null);
}
function chooseTag(tagName, element) {
	document.form.tag.value = tagName;
	setTagsColor('#000000');
	element.style.color="red";
}

/*
function resetTagStyle(theClass) {
	var allPageTags=document.getElementsByTagName("a");
	for (i = 0; i < allPageTags.length; i++) {
		if (allPageTags[i].className == theClass) {
			allPageTags[i].style.color='#000000';
		}
	}
}
*/